package com.yeshen.pmtea.fragments;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.yeshen.pmtea.R;
import com.yeshen.pmtea.adapters.NewsAdapter;
import com.yeshen.pmtea.beans.News;
import com.yeshen.pmtea.beans.Urls;
import com.yeshen.pmtea.callback.NewsCallback;
import com.yeshen.pmtea.net.NewsAsyncTask;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class FourFragment extends Fragment {
    private ListView mListView;
    private List<News> mNewsList;
    private NewsAdapter mAdapter;

    public FourFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_four, container, false);
        mListView= (ListView) view.findViewById(R.id.fourToListView);
        mNewsList =new ArrayList<>();

        new NewsAsyncTask(new NewsCallback() {
            @Override
            public void callbackNews(List result) {
                mNewsList.remove(mNewsList);
                mNewsList.addAll(result);
                mAdapter.notifyDataSetChanged();
            }
        }).execute(Urls.HEADLINE_URL+Urls.OPERATE_TYPE+4);
        mAdapter =new NewsAdapter(mNewsList,getContext());
        mListView.setAdapter(mAdapter);
        return view;
    }

}
